3 Fixed typos edited Apr 6 at 23:22 m_goldberg 92.6k88 gold badges7676 silver badges211211 bronze badges This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out problemsome problems I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it won't. but I hope this helphelps you to move forward with your code. Caution — this code has not been tested. This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out problem I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it won't. but I hope this help you to move forward with your code. Caution — this code has not been tested. This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out some problems I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it won't. but I hope this helps you to move forward with your code. Caution — this code has not been tested. 2 fixed typo edited Apr 6 at 12:00 Nasser 63.5k44 gold badges9393 silver badges218218 bronze badges This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out problem I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it worn'twon't. but I hope this help you to move forward with your code. Caution — this code has not been tested. This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out problem I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it worn't. but I hope this help you to move forward with your code. Caution — this code has not been tested. This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out problem I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it won't. but I hope this help you to move forward with your code. Caution — this code has not been tested. 1 answered Apr 6 at 6:46 m_goldberg 92.6k88 gold badges7676 silver badges211211 bronze badges This is not a complete answer. There is no way I can debug the code you post which is incomplete. But I can point out problem I see in your code. Here your code rewritten to correct what to appear to obvious bugs add comments indicating possible problems add comments indicating better practice λ = 0.15; shh = {}; nC := Ceiling[(nA + nB)/2] (* how will na and nb get values? *) v21 := NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; lengtshh := Total[Map[ArcLength, Map[Line, dum]]] (* how will dum get a value? *) With[{max = 10, αmax = 2}, (* work with small nubers for debugging *) Module[{nA, nB, n3, n}, (* localize auxiliary variables *) Do[ nA = Round[5.7/λ^2*0.5]; nB = Round[5.7/λ^2*1.5]; Do[ n := nC; (* this looks it might be a bug; maybe = intended?*) n3 = NotebookEvaluate[$UserDocumentsDirectory <> "/V21.nb"]; If[n3 == "Percolated", nB = nC, nA = nC]; If[nB - nA == 1 && n3 == "Percolated", shh = AppendTo[shh, {n, lengtshh}]; Break[]]; If[nB - nA == 1 && n3 == "not Percolated", n = n + 1; v21; shh = AppendTo[shh, {n, lengtshh}]; Break[]], i], {α, αmax}]]]  The is no guarantee that this will fix all your problems. I suspect it worn't. but I hope this help you to move forward with your code. Caution — this code has not been tested.