Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How to give a command like goto

2 vues (au cours des 30 derniers jours)
Eddy Iswardi
Eddy Iswardi le 7 Juin 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Walter Roberson
Walter Roberson le 7 Juin 2020
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

Cette question est clôturée.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by