Control Flow

Managing logic with conditionals and loops.

If / Else (`jodi` / `nahole`)

BanglaCode uses jodi for if and nahole for else.

dhoro age = 20;jodi (age >= 18) {dekho("Adult"); } nahole {dekho("Minor"); }

Switch Statement (`bikolpo`)

Use bikolpo (switch) with khetre (case) clauses and manchito (default):

1// Basic switch statement
2bikolpo (day) {
3 khetre 1 {
4 dekho("Monday");
5 thamo; // Break to avoid fall-through
6 }
7 khetre 2 {
8 dekho("Tuesday");
9 thamo;
10 }
11 khetre 3 {
12 dekho("Wednesday");
13 thamo;
14 }
15 manchito {
16 dekho("Other day");
17 }
18}
19
20// Switch with expressions
21dhoro score = 85;
22bikolpo (score / 10) {
23 khetre 9 {
24 dekho("Grade: A");
25 thamo;
26 }
27 khetre 8 {
28 dekho("Grade: B");
29 thamo;
30 }
31 khetre 7 {
32 dekho("Grade: C");
33 thamo;
34 }
35 manchito {
36 dekho("Grade: F");
37 }
38}
39
40// Switch with string values
41dhoro action = "save";
42bikolpo (action) {
43 khetre "save" {
44 dekho("Saving file...");
45 thamo;
46 }
47 khetre "delete" {
48 dekho("Deleting file...");
49 thamo;
50 }
51 khetre "edit" {
52 dekho("Editing file...");
53 thamo;
54 }
55 manchito {
56 dekho("Unknown action");
57 }
58}

Loops

While Loop (`jotokkhon`)

dhoro i = 0;jotokkhon (i < 5) {dekho(i); i = i + 1; }

For Loop (`ghuriye`)

ghuriye (dhoro i = 0; i < 5; i = i + 1) {dekho("Count: ", i); }