English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include

main()
{
int i,j,k;

for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)

{
if(i==3&&j==3&&k==3)
goto out;
else
printf("i=%d j=%d k=%d\n",i,j,k);
}
}
}
out:
printf("Out of the loop at last!!!!");
}

2007-10-09 00:19:25 · 1 answers · asked by vanshi 1 in Computers & Internet Programming & Design

1 answers

You don't need the "if ... go out".
Three NESTED loops.
i = 1, j = 1, loop the k: 1, 2, 3
exits k, run loop j=2, start loop k, 1,2,3
exit k, run loop j=3, start loop k: 1, 2, 3
When loop j reaches 3, loop i does the next iteration: i = 2 and loop again.
When loop i reaches 3, all loops stop: exit.

2007-10-09 00:39:28 · answer #1 · answered by just "JR" 7 · 0 0

fedest.com, questions and answers