Difference between revisions of "SHIP:Sail:Flow Control:break"

From Serious Documentation
Jump to: navigation, search
Line 3: Line 3:
 
*[[SHIP:Sail:Flow_Control|Flow_Control]]
 
*[[SHIP:Sail:Flow_Control|Flow_Control]]
 
*[[SHIP:Sail:Flow_Control:continue|continue]]
 
*[[SHIP:Sail:Flow_Control:continue|continue]]
 +
*[[SHIP:Sail:Flow_Control:switch|switch]]
  
== {{SHIP:Sail:Flow_Control:break|break}} ==
+
== [[SHIP:Sail:Flow_Control:break|break]] ==
 
<onlyinclude>Causes execution to exit from a loop or switch statement branch.
 
<onlyinclude>Causes execution to exit from a loop or switch statement branch.
  
Line 11: Line 12:
 
! scope="col" style="text-align:left" | Description
 
! scope="col" style="text-align:left" | Description
 
|-
 
|-
|{{Flow_Control:break|break}}||Causes immediate termination out of a loop or switch block.
+
|[[Flow_Control:break|break]]||Causes immediate termination out of a loop or switch block.
 
|}</onlyinclude>
 
|}</onlyinclude>
 
== Example ==
 
== Example ==
<code>
+
<source lang = "c">
 
a = 10;
 
a = 10;
 
while(a)
 
while(a)
Line 21: Line 22:
 
       break;
 
       break;
 
   printf("%d,", a);
 
   printf("%d,", a);
}</code>
+
}</source>
 
Prints:
 
Prints:
 
10,9,8,7,6
 
10,9,8,7,6
Line 27: Line 28:
 
or
 
or
  
<code>
+
<source lang="c">
 
switch(a)
 
switch(a)
 
{
 
{
Line 40: Line 41:
 
       printf("4");
 
       printf("4");
 
   default;
 
   default;
}</code>
+
}</source>
 
Prints:
 
Prints:
 
a = 1 ->123
 
a = 1 ->123
Line 46: Line 47:
 
a = 3 ->3
 
a = 3 ->3
 
a = 4 ->4
 
a = 4 ->4
 +
 +
[[Category:Flow Control Statements]]

Revision as of 10:56, 4 October 2016

See Also

break

Causes execution to exit from a loop or switch statement branch.

Statement Description
break Causes immediate termination out of a loop or switch block.

Example

a = 10;
while(a)
{
   if(a == 5)
      break;
   printf("%d,", a);
}

Prints: 10,9,8,7,6

or

switch(a)
{
   case 1:
      printf("1");
   case 2:
      printf("2");
   case 3:
      printf("3");
      break;
   case 4:
      printf("4");
   default;
}

Prints: a = 1 ->123 a = 2 ->23 a = 3 ->3 a = 4 ->4