How to color different table's cell in a loop?

Hi there,

I have acoding like this:

 for (int i = 0; i < ssAAssetCritical.GetLength(0); i++)
 {
     for (int j = 0; j < ssAAssetCritical.GetLength(1); j++)
     {
         Color colorme;
         if (whichAnnex == "ssFRiskTolerances")
         {
             if (j == 0)
             {
                 colorme = Color.Yellow;
             }
             else if (j == 1)
             {
                 colorme = Color.Blue;
             }
             else if (j == 2)
             {
                 colorme = Color.Green;
             }
             else
             {
                 colorme = Color.Pink;
             }
             builder.CellFormat.Shading.BackgroundPatternColor = colorme;
         }
 Aspose.Words.Font font2 = builder.Font;
 font2.Bold = false;
 font2.Name = "Calibri";
 font2.Size = 10;

 builder.InsertCell();
 builder.CellFormat.SetPaddings(0, 0, 0, 0);
 builder.ParagraphFormat.SpaceBefore = 0;
 builder.ParagraphFormat.SpaceAfter = 0;

But i cannot understand, why the result only 1 blue and two greens.
should be 1 yellow, 1 blue, and last green
as the length is 3.

regards

Sorry,
i found the answer - insert cell first, then do the format later…
regards

@ibox It is perfect that you managed to achieve what you need. Please feel free to ask in case of any other issues. We will be glad to help you.