Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Nested For Loop [EXAMPLES!]

Name: ALPHA 2011-07-05 13:38

Hi,
Here is a collection of few examples for NESTED FOR LOOP.
Simple codes in how to use nested loops,
There is only the code, no explanation (not good at explaining anything)
So, just try to understand the program
Hope this will help as much people as possible
Let's Stop talking and just begin

OK
Here we go!

1.Get the following output :
a.
1
12
123
1234
12345
123456
1234567
12345678
123456789

//Numbers Ladder
//Nested Loops
//By ALPHA
//On 22 Oct 2008
//www.CodeCall.net
//----------------------
public class testFor
{
    public static void main(String [] args)
    {
        for (int i=1; i<=9; i++)
        {
            System.out.println();
            for (int j=1; j<=i; j++)
            {
                System.out.print(j);
            }
        }
      System.out.println();
    }
}

Name: Anonymous 2011-07-07 16:34

No use of the goes-to operator? Shame on you, /prog/ !

#include <cstdio>
#define MAX 10

int main(int argc, const char * argv[]) {
    int i = MAX;
    int j;
    while (i --> 1) {
        j = MAX;
        while (j --> i)
            printf("%i", MAX - j);
        printf("\n");
        }
    return 0;
    }

Name: Anonymous 2011-07-07 17:45

>>41
This operator is superior.
#include <cstdio>
#define MAX 10

int main(int argc, const char * argv[]) {
  int i = 1;
  int j;
  while (i ++< MAX) {
      j = 1;
      while (j ++< i)
          printf("%i", j-1);
      printf("\n");
      }
  return 0;
}

Name: Anonymous 2011-07-07 17:51

print '\n'.join(''.join(map(str, xrange(1, i+1))) for i in xrange(1,10))

Ironic how the FIOC version has no indentation. Problem Lispfags?

Name: Anonymous 2011-07-07 18:01

Name: Anonymous 2011-07-07 18:16

>>42
66went to99 operator considered harmful

Name: Anonymous 2011-07-07 18:51

<?php
for ($i = 1; $i < 10; $i++) {
    echo implode(range(1, $i)), "\n";
}

Name: Anonymous 2011-07-07 19:16

>>45
My bad. How's this?

#include <stdio.h>

int main(void) {
  int i = 1
  int j;
  durr:
  j = 1;
  hurr:
  printf("%d", j);
  j++;
  if (j <= i) goto hurr;
  printf("\n");
  i++;
  if (i < 10) goto durr;
}

Name: Anonymous 2011-07-07 22:58

>>39
java ``faggot''

Name: Anonymous 2011-07-08 0:25

([\~] 1..9)>>.say;

nested for what now?

Name: Anonymous 2011-07-08 1:03

>>49
At first, I thought it was Haskell, then APL. Then I realized it was Perl 6.

Name: Anonymous 2011-07-08 1:23

>>50
I think that's a good thing. This code isn't typical (or even correct, it works but >> and side-effects are non-deterministic) but there's been a lot of Haskell influence on the Perl 6 implementers and probably a good amount of APL influence on Larry Wall.

Name: Anonymous 2011-07-08 1:34

>>40
I forgot to change a java statement when I rewrote it in C# (They're pretty much the same language):

namespace ForLoopsAreStillForFags{
    class Program
    {
        static void Main(string[] args)
        {
            int i = -1, j;
            while (i++ <= 9)
            {
               j = -1;
               while (j++ <= i) Console.Write(j);
               Console.WriteLine();
            }
        }
    }
}


If you must have for loops:



namespace ForLoopsAreStillForFags{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 0; i <= 9; i++)
            {
                for(int j = 0; j <= 9; j++)
                    Console.Write(j);
                Console.WriteLine();
            }
        }
    }
}


>>48
Actually, no. C++ "faggot"

Name: Anonymous 2011-07-08 2:12

I wish Java had closures and attributes and I wish C# had anonymous/inner classes.

In general though I wish a large corporation would back a streamlined, simple, extensible language. The closest things are Blizzard's support of Lua and Google's of Python.

Name: Anonymous 2011-07-08 2:22

APL
influence
If anything, being influenced by APL is a Very Bad Thing.

Name: Anonymous 2011-07-08 2:28

>>54
What's wrong with nice array operations?

Name: Anonymous 2011-07-08 3:17

both array processing and list processing are cool and I feel like I'm wading around in molasses when I write C.

There I said it.

Name: ARRay Processor 2011-07-08 4:00

{ "defun", "sum-of-squares", { "x", "y" },
  { "+", { "*", "x", "x" }, { "*", "y", "y" } } }

Name: Anonymous 2011-07-08 4:05

>>57
ONE WORD: THE FORCED SUMMATION OF THE SQUARES. THREAD OVER

Name: Anonymous 2011-07-08 6:11

#include <stdio.h>

#include <ooc/ooc.h>
#include <ooc/lang/Integer/Integer.h>
#include <ooc/lang/String/String.h>
#include <ooc/util/LinkedQueue/LinkedQueue.h>

int main(void) {
  int i;
  Generic *myQueue;

  myQueue = new(LinkedQueue());

  for (i = 1; i < 10; i++) {
    Queue.add(myQueue, new(Integer(), i));
    putfree(String.replace(toString(myQueue), ", ", ""));
  }

  foreach (i, myQueue)
    del(i);

  del(myQueue);

  return 0;
}

Name: Anonymous 2011-07-08 6:13

one word: the forced ejaculation of the penis. thread over

Name: VIPPER 2011-07-08 7:03

COBOL cabal
Haskell shekels
Java barmitzvah

Name: Anonymous 2011-07-08 9:12

>>59
Your enterprise level is low

type
 TNumberGenEnumerator = class
 private
  fNumbers,
  fCurrent: longint;
 public
  constructor Create(ANumbers: longint);

  function GetCurrent: longint;
  function MoveNext: Boolean;
  property Current: longint read GetCurrent;
 end;

 INumberGen = interface
  function GetEnumerator: TNumberGenEnumerator;
 end;

 INumberGenFactory = interface
  function GetInstance(ANumbers: longint): INumberGen;
 end;

 TNumberGen = class(TInterfacedObject, INumberGen)
 private
  fNumbers: longint;
 public
  function GetEnumerator: TNumberGenEnumerator;
  constructor Create(ANumbers: longint);
 end;

 TNumberGeneratorFactory = class(TInterfacedObject, INumberGenFactory)
  function GetInstance(ANumbers: longint): INumberGen;
 end;

constructor TNumberGenEnumerator.Create(ANumbers: longint);
begin
   inherited Create;
   fCurrent := 0;
   fNumbers := ANumbers;
end;

function TNumberGenEnumerator.GetCurrent: longint;
begin
   result := fCurrent;
end;

function TNumberGenEnumerator.MoveNext: Boolean;
begin
   inc(fCurrent);
   result := fCurrent <= fNumbers;
end;

function TNumberGen.GetEnumerator: TNumberGenEnumerator;
begin
   result := TNumberGenEnumerator.Create(fNumbers);
end;

constructor TNumberGen.Create(ANumbers: longint);
begin
   inherited Create;
   fNumbers := ANumbers;
end;

function TNumberGeneratorFactory.GetInstance(ANumbers: longint): INumberGen;
begin
   result := TNumberGen.Create(ANumbers);
end;

procedure WriteNumbers;
var i, num: longint;
begin
   for i := 1 to 9 do
   begin
      for num in INumberGenFactory(TNumberGeneratorFactory.Create).GetInstance(i) do
         write(num);
      writeln;
   end;
end;

Name: Anonymous 2011-07-08 10:40

>>62
Pascal <3. ;_;

Name: Anonymous 2011-07-08 12:58

Nintendo 64 get.

Name: Anonymous 2011-07-08 14:56

>>63
Pascal is a pointless bastardized version of C.

Name: Anonymous 2011-07-08 17:01

>>65
I like its arrays.

Name: Anonymous 2011-07-09 21:11

>>43
print '\n'.join('123456789'[0:i] for i in xrange(1,10)])

Name: Anonymous 2011-07-09 21:17

>>67
'\n'.join(

Name: Anonymous 2011-07-09 21:23

>>68
Yes, that's what it says.

Name: Anonymous 2011-07-09 21:31

>>67
You must have missed the title of the thread.

Name: Anonymous 2011-07-09 21:43

>>70
You must have missed the rest of the thread.

Name: Anonymous 2011-07-09 22:35

>>54
That's not fair. Array processing in APL is mad skills and that influence shows in this example. I'd argue Perl 6 doesn't quite have enough influence in that regard.

Name: Anonymous 2011-07-09 23:11

Oh, did someone mention APL? Here you go:

⍳¨⍳9

Name: Anonymous 2011-07-10 0:28

>>71
print """1
12
123
1234
12345
123456
1234567
12345678
123456789"""


How's that then?

Name: Anonymous 2011-07-10 1:06

1
12
123
1234
12345
123456
1234567
12345678
123456789

English language. Beat that.

Name: Anonymous 2011-07-10 2:48

worst thread ever

Name: Anonymous 2011-07-12 15:56

You are a wizard, Anon.

Name: Anonymous 2011-07-13 0:29

>>75
What are you talking about? All I see is code with syntax errors.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List