How to print 1 to 10 numbers in Visualforce page in Salesforce?

How to print 1 to 10 numbers in Visualforce page in Salesforce?

Sample Code:

Visualforce page:

<apex:page controller="Sample" sidebar="false">
    <apex:pageBlock >
        <apex:repeat value="{!numbers}" var="num">
            <apex:outputText >{!num}</apex:outputText>
            <br/>  
        </apex:repeat>
    </apex:pageBlock>
</apex:page>

Apex Controller:

public class Sample
{  
    public List<Integer> numbers {get;set;}
    Transient Integer i=0;
   
    public Sample()
    {
        numbers = new List<Integer>();
        for(i=1;i<11;i++)
        {
            numbers.add(i);
        }
    }
}

Output:

Leave a Reply