my code keep running continuously with no stop ... help appreciate

9 ビュー (過去 30 日間)
Njud Alotaibi
Njud Alotaibi 2021 年 9 月 25 日
コメント済み: Image Analyst 2021 年 9 月 25 日
Hi all,
I have my code here i tried sevral time with many suggetuon between break and while loop but keep running with no stop.
I need to test all element in nodes lalel to meet the conditions and then if the node label set meet the condition stop and give me answer(it sould test all the for loop). node label is the random perm.
this my matlab version (MATLAB : Version 9.10 (R2021a))
code:
nodeslabel=[0,randperm(4)]
for i=1:n
for j=1:n
if i~=j
if % condition met (print)
else
% exist the all if condition and for for loops and make
% new nodeslabel=[0,randperm(4)] till if conditon met
end
end
end
end
  1 件のコメント
Image Analyst
Image Analyst 2021 年 9 月 25 日
This code:
nodeslabel=[0,randperm(4)]
for i=1:n
for j=1:n
if i~=j
if % condition met (print)
else
% exist the all if condition and for for loops and make
% new nodeslabel=[0,randperm(4)] till if conditon met
end
end
end
end
does not have a while loop and will not be an infinite loop unless n is infinite. Either post the actual code with a while loop in it, or step through it with the debugger. Evidently you're not debugging your code by stepping through it line by line and I'm wondering why not.

サインインしてコメントする。

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 9 月 25 日
In your code, [while ... loop] has to be eliminated and then everything else works ok.
% while true % To be eliminated
...
% end
  3 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 9 月 25 日
then there must be the condition to set while operator to halt, e.g.:
Halt = 1;
while Halt == 1
...
% Condition is met
Halt = 0;
end
Njud Alotaibi
Njud Alotaibi 2021 年 9 月 25 日
編集済み: Njud Alotaibi 2021 年 9 月 25 日
I've tried that unfortunatly doesn't do the process again and give me the sol when the condition met.
I really want same this idea after else and if ...
nodeslabel=[0,randperm(4)]
for i=1:n
for j=1:n
if i~=j
if % condition met (print)
else
% exist the all if condition and for for loops and make
% new nodeslabel=[0,randperm(4)] till if conditon met
end
end
end
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by