You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-4Lines changed: 82 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -409,7 +409,7 @@ class Sample{
409
409
410
410
Note : Proper Code will be given in the file name as [wrap.java](https://github.com/ackwolver335/Java-Coder/blob/main/wrap.java) Click to go on it.
411
411
412
-
## Intro to Decision Making
412
+
## Intro to Decision Making :
413
413
414
414
Decision Making in programming is similar to decision-making in real life. In programming also face some situations where we want a certain block of code to be executed when some condition is fulfilled.
415
415
@@ -421,12 +421,16 @@ Decision Making in programming is similar to decision-making in real life. In pr
421
421
- if else if ladder : Here, a user can decide among multiple options.The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that ‘if’ is executed, and the rest of the ladder is bypassed.
422
422
- Switch Case : These are other kinds of block of statements that are used in order to run a particular block of code in regarding a particular case or value.
423
423
424
-
Note : Proper Code is given in the file [decision.java](https://github.com/ackwolver335/Java-Coder/blob/main/decision1.java) Click to go on it.
425
-
426
424
### Here are some code examples of Decision Making Statements :
427
425
428
426
**If Statements**
429
427
428
+
- If statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e if a certain condition is true then a block of statements is executed otherwise not.
429
+
430
+
- The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false? Here comes the else statement. We can use the else statement with the if statement to execute a block of code when the condition is false.
431
+
432
+
- A nested if is an if statement that is the target of another if or else. Nested if statements mean an if statement inside an if statement. Yes, java allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.
433
+
430
434
```
431
435
class Class_name{
432
436
public static void main(String[] args){
@@ -459,6 +463,80 @@ class Class_name{
459
463
}
460
464
```
461
465
466
+
**Switch Statement**
467
+
468
+
- The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
469
+
470
+
```
471
+
class Class_name{
472
+
public static void main(String[] arg){
473
+
int num1 = 5;
474
+
475
+
switch(num1){
476
+
case 1:
477
+
System.out.println("Value is : 1");
478
+
break; // for stopping the case here only
479
+
480
+
case 2:
481
+
System.out.println("Value is : 2");
482
+
break;
483
+
484
+
case 5:
485
+
System.out.println("Value is : 5");
486
+
break;
487
+
488
+
default:
489
+
System.out.println("Hope you got required result!");
490
+
}
491
+
}
492
+
}
493
+
```
494
+
495
+
Note : Proper Code is given in the file [decision.java](https://github.com/ackwolver335/Java-Coder/blob/main/decision1.java) Click to go on it.
496
+
497
+
## Looping Structures :
498
+
499
+
Looping in programming languages is a feature which facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true. Java provides three ways for executing the loops.
500
+
501
+
**Categories of Looping Structures :**
502
+
503
+
- while Loop : A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
504
+
505
+
```
506
+
while(condition){
507
+
// code block
508
+
// stopping condition here
509
+
}
510
+
```
511
+
512
+
- for Loop : for loop provides a concise way of writing the loop structure. Unlike a while loop, a for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.
513
+
514
+
```
515
+
for(initiator;condition;increment){
516
+
// code here
517
+
}
518
+
```
519
+
520
+
- do-while loop : do while loop is similar to while loop with only difference that it checks for condition after executing the statements, and therefore is an example of Exit Control Loop.
521
+
522
+
```
523
+
do{
524
+
// code here
525
+
// stopping condition here
526
+
} while(testing_condition);
527
+
```
528
+
529
+
- for-each loop : For-each is another array traversing technique like for loop, while loop, do-while loop introduced in Java5.
530
+
531
+
### Jump Statements :
532
+
533
+
Jump Statements are those statements which are used to come out of a particular block of code or looping structures that are explained above and there are different keywords that are used in the Jump Statements !
534
+
535
+
-**break** : Used to break the loop or code block there only and then the cursor comes out of the block.
536
+
-**continue** : Used to stops a particular iteration in loops or skip any particular iteration in the code block.
537
+
538
+
Note : Proper code is beeng given in [loops.java](https://github.com/ackwolver335/Java-Coder/blob/main/loops.java) file above !
0 commit comments