Message Boards Message Boards

0
|
161 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to use Catch multiple times inside a loop (For)?

Posted 1 month ago

Hello. I'm still learning the tricks, it's been only two months but I'm slightly better than when I started. So I discovered Catch function a month ago, It's a cool function! But lately I wanted to use it inside a loop to define a certain function (extracttttC4) - basically It extract the subgroup isomorphic to Z/4Z inside a bigger parent group so I can arrive to my ultimate goal which to count the maximal chains of the group C2C4C8*C16- A subgroup isomorphic to C4 is represented by a list of length 2 e.g.

{{0, 0, 0, 4}, {0, 0, 0, 8}} (*  by the way everything is Mod {2,4,8,16}*)

Now , When I execute this part of the function alone on another notebook:

list = {{0, 0, 0, 8}, {0, 0, 4, 0}, {0, 0, 0, 4}, {0, 2, 0, 0}, {1, 1,2,0}};
 list01= {{{1, 1, 2, 0}}, {{0, 0, 0, 4}, {0, 0, 0, 8}}};
For[ k = 1, k <= Length[list01], k++,
       If[Length[list01[[k]]] == 1, Catch[
         Do[Do[
           Do[ Which[
             list[[j]] != list[[i]] && 
              Mod[2*list01[[k]][[1]], {2, 4, 8, 16}] == 
               list[[j]] + list[[i]], 
             list01[[k]] = Append[list01[[k]], list[[i]]]];
            If[Length[list01[[k]]] == 2, Throw[list01, "myTag"]], {k, 1, 
             Length[list01]}], {j, 1, 5}], {i, 1, 5}],
         "myTag"
                          ]]
       ];
  the (mini test)program gives as a result
{{{1, 1, 2, 0}}, {{0, 0, 0, 4}, {0, 0, 0, 8}}}  whereas I want this 
   {{{1, 1, 2, 0}, {0, 0, 4, 0}}, {{0, 0, 0, 4}, {0, 0, 0, 8}}}

I know why It does this because Length[list01[[1]]] == 2 and it stops without testing the case where k=2.
I saw somebody in another forum that said we can use Catch multiple times, So I just tried to use someting like Throw[list01, "myTag"], "myTag"], but It didn't work.
Any help would be greatly appreciated.
P.S:sorry for the long post

POSTED BY: Issam EL MARIAMI
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract