> For the complete documentation index, see [llms.txt](https://programmingfundamental.gitbook.io/programmingwithjava/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://programmingfundamental.gitbook.io/programmingwithjava/obektno-orientirano-programirane-1-chast/laboratorno-uprazhnenie-1/break.md).

# Break

Прекратява оператора който се изпълнява в момента:

### Пример за break в while loop

```
public class BreakExample1 {
   public static void main(String[] args){
      int num =0;
      while(num<=100)
      {
          System.out.println("Value of variable is: "+num);
          if (num==2)
          {
             break;
          }
          num++;
      }
      System.out.println("Out of while-loop");
  }
}
```

**Изход:**

```
Value of variable is: 0
Value of variable is: 1
Value of variable is: 2
Out of while-loop
```

### Пример за break в for loop

```
public class BreakExample2 {

public static void main(String[] args){
	int var;
	for (var =100; var>=10; var --)
	{
	    System.out.println("var: "+var);
	    if (var==99)
	    {
	         break;
	    }
	 }
	 System.out.println("Out of for-loop");
   }
}
```

**Output:**

```
var: 100
var: 99
Out of for-loop
```

### Пример за break в switch-case

```
public class BreakExample3 {

   public static void main(String[] args){
	int num=2;
	      
	switch (num)
	{
	    case 1:
	       System.out.println("Case 1 ");
	       break;
	    case 2:
	       System.out.println("Case 2 ");
	       break;
	    case 3:
	       System.out.println("Case 3 ");
	       break;
	    default:
	       System.out.println("Default ");
	}
   }
}
```

**Изход:**

```
Case 2
```
