The first input below defines a function.  The next two show examples of using this defined function.

f[x_] = x^2 - 2

f[4]

f[z]

The following two inputs show use of the Mathematica function N.

N[3/4]

N[Pi, 20]

Here is our first version of the bisection algorithm.  You can change f, a, b, and tol and then execute the code again.

f[x_] = x^2 - 2;
a = 0;
b = 2;
tol = 10^-4;
While[(b - a)/2 > tol, 
c = 
          N[(a + b)/2]; 
Print[
          c]; 
If[f[c] == 0, 
          Print[c], 
If[f[a]*f[c] < 0, b = c, 
            a = c]
]
];

Here is our second version incorporating a maximum number of iterations.

f[x_] = x^2 - 3;
a = 0;
b = 1;
tol = 10^-4;
m = 5;
i = 0;
While[(b - a)/2 > tol  &&  
          i ≤  m, 
i = 
          i + 1; 
c = 
          N[(a + b)/2]; 
Print[
          c]; 
If[f[c] == 0, 
          Print[c], 
If[f[a]*f[c] < 0, b = c, 
            a = c]
]
];

This third version increments the iteration index using the "++" method.  Note that this adds 1 to i but returns the old value of i to be used in the test.

f[x_] = x^2 - 3;
a = 0;
b = 1;
tol = 10^-4;
m = 5;
i = 0;
While[(b - a)/2 > tol  &&  i++ ≤  
            m, 
c = 
          N[(a + b)/2]; 
Print[
          c]; 
If[f[c] == 0, 
          Print[c], 
If[f[a]*f[c] < 0, b = c, 
            a = c]
]
];