Q:

How to Use Do-while loop In Apex?

Currently my issue is that I want to Fetch Bank Detail Until Its Status Changes From null to Any value.
I am using Do while loop and my issue are the iterations is running the only once. Not able to find the exact reason for this. 
Here is Code snippet
Bank_Statement__c bankDetail= new Bank_Statement__c ();

        do
        {
            i++;
            bankDetail = [SELECT Id ,Status__c
                         FROM Bank_Statement__c WHERE ID=:randomId LIMIT 1];
            System.Debug('bank '+bankDetail.Status__c);
            System.Debug(bankDetail);
        }
        while(bankDetail.Status__c!= null); 

A:

There doesn't appear to be anything wrong with your do-while syntax. However, it looks like there's a problem with your logic and what you're trying to accomplish that goes against best practices. You shouldn't place SOQL queries into iterative loops. It's inefficient and puts you at risk of exceeding Salesforce governor limits. Second, your loop is most likely returning after one iteration because it's finding a Bank_Statement__c record on its first pass that has a non-null status. What do your debug statements output?
Why do you want to continuously query for this record until the status changes? What do you want to do once the status is set? If you're most interested in reacting to this field change, I would look into platform events, triggers, or process builder. Having a polling process within an Apex class is not the way to go about this.

