Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to give a command like goto

2 ビュー (過去 30 日間)
Eddy Iswardi
Eddy Iswardi 2020 年 6 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have code like this
clc;
clear;
questions = {'Stick Up = '
'Stick = '
'Stuck = '
'Safe = '
'Built-in = '};
QandA = {'Stick Up = ', 'merampok/membela';
'Stick = ', 'tongkat';
'Stuck = ', 'menusuk/memasukkan';
'Safe = ','aman/brangkas';
'Built-in = ','terpasang'};
qorder = randperm(numel(questions));
QandAreordered = QandA(qorder,:);
for qidx = 1:size(QandAreordered, 1)
%return here
answer = input(QandAreordered{qidx, 1}, 's');
if strcmp(answer,QandAreordered{qidx, 2})
fprintf('Correct\n\n');
else
fprintf('You''re thrown off the bridge\n\n');
end
end
if I get false condition or fprintf('You''re thrown off the bridge\n\n'), how repeat algorithm to %return here

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 6 月 7 日
for qidx = 1:size(QandAreordered, 1)
while true
answer = input(QandAreordered{qidx, 1}, 's');
if strcmp(answer,QandAreordered{qidx, 2})
fprintf('Correct\n\n');
break;
else
fprintf('You''re thrown off the bridge\n\n');
end
end
end

この質問は閉じられています。

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by